package cn.xiaolang.function.design_pattern.strategyAdapter;

/**
 * @author Dean
 * @date 2021-01-19
 */
public class OriginalApplySample {

    public static void main(String[] args) {
        double originalPrice = 1000d;
        System.out.println(settleAmount(PayTypeEnum.PAY_BANK, originalPrice));
        System.out.println(settleAmount(PayTypeEnum.PAY_ALI_PAY, originalPrice));
        System.out.println(settleAmount(PayTypeEnum.PAY_WEB_CHAT, originalPrice));
    }

    private static double settleAmount(PayTypeEnum payTypeEnum, double originalPrice) {
        OrderSettlement settlement;
        if (PayTypeEnum.PAY_ALI_PAY.equals(payTypeEnum)) {
            settlement = new SettleAliPay();
        } else if (PayTypeEnum.PAY_BANK.equals(payTypeEnum)) {
            settlement = new SettleBank();
        } else if (PayTypeEnum.PAY_WEB_CHAT.equals(payTypeEnum)) {
            settlement = new SettleWebChat();
        } else {
            return originalPrice;
        }
        return new SettlementContext(settlement).settlement(originalPrice);
    }
}
